# Maintainer: Maksim Bondarenkov <maksapple2306@gmail.com>

_realname=tuxpaint
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}"
         "${MINGW_PACKAGE_PREFIX}-${_realname}-docs")
pkgver=0.9.34
pkgrel=2
pkgdesc='Drawing program designed for young children (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://tuxpaint.org/'
license=('spdx:GPL-2.0-only')
depends=("${MINGW_PACKAGE_PREFIX}-cairo"
         "${MINGW_PACKAGE_PREFIX}-gettext-runtime"
         "${MINGW_PACKAGE_PREFIX}-zlib"
         "${MINGW_PACKAGE_PREFIX}-libpng"
         "${MINGW_PACKAGE_PREFIX}-fontconfig"
         "${MINGW_PACKAGE_PREFIX}-pango"
         "${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-fribidi"
         "${MINGW_PACKAGE_PREFIX}-librsvg"
         "${MINGW_PACKAGE_PREFIX}-libimagequant"
         "${MINGW_PACKAGE_PREFIX}-SDL2"
         "${MINGW_PACKAGE_PREFIX}-SDL2_image"
         "${MINGW_PACKAGE_PREFIX}-SDL2_gfx"
         "${MINGW_PACKAGE_PREFIX}-SDL2_mixer"
         "${MINGW_PACKAGE_PREFIX}-SDL2_pango"
         "${MINGW_PACKAGE_PREFIX}-SDL2_ttf")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-gperf"
             "${MINGW_PACKAGE_PREFIX}-imagemagick"
             "${MINGW_PACKAGE_PREFIX}-libpaper"
             "${MINGW_PACKAGE_PREFIX}-gettext-tools")
options=('!emptydirs')
optdepends=(#"${MINGW_PACKAGE_PREFIX}-tuxpaint-stamps: more stamps"
            #"${MINGW_PACKAGE_PREFIX}-tuxpaint-config: configuration manager"
            "${MINGW_PACKAGE_PREFIX}-fontforge: zh_tw doc generator script")
source=("https://downloads.sourceforge.net/sourceforge/tuxpaint/${_realname}-${pkgver}.tar.gz"
        "001-makefile.patch")
sha256sums=('b761df5ed386a9e04a6809ab3e0cbf2126f10b770527cb2b5f190ff5e370ed03'
            'a9f6428c6e23c9869db450999e6181a487dd9ec36070a1c8bc5cd69b8ff41e85')
noextract=("${_realname}-${pkgver}.tar.gz")

prepare() {
  tar -xzf "${_realname}-${pkgver}.tar.gz" || true
  cd "${_realname}-${pkgver}"

  patch -Np1 -i "${srcdir}/001-makefile.patch"
}

build() {
  make -C "${_realname}-${pkgver}"\
    PREFIX="${MINGW_PREFIX}" \
    LDFLAGS="${LDFLAGS}" \
    OPTFLAGS="${CFLAGS} -ffast-math" FASTMATH="${CFLAGS} -ffast-math" \
    all
}

package_tuxpaint() {
  backup=("${MINGW_PREFIX:1}/etc/tuxpaint/tuxpaint.conf")

  make -C "${_realname}-${pkgver}" \
    PREFIX="${MINGW_PREFIX}" \
    GNOME_PREFIX="${MINGW_PREFIX}" \
    COMPLETIONDIR="${pkgdir}${MINGW_PREFIX}/share/bash-completion/completions" \
    DESTDIR="${pkgdir}" \
    PACKAGE_ONLY=yes \
    install

  mkdir -p "dest${MINGW_PREFIX}/share/doc"
  mv "${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}-${pkgver}" "dest${MINGW_PREFIX}/share/doc/${_realname}"
}

package_tuxpaint-docs() {
  pkgdesc+=" (Documentation)"
  depends=()
  optdepends=()

  mv dest/* "${pkgdir}"
}

# template start; name=mingw-w64-splitpkg-wrappers; version=1.0;
# vim: set ft=bash :

# generate wrappers
for _name in "${pkgname[@]}"; do
  _short="package_${_name#${MINGW_PACKAGE_PREFIX}-}"
  _func="$(declare -f "${_short}")"
  eval "${_func/#${_short}/package_${_name}}"
done
# template end;
